package com.htfyun.nvrom;

import java.io.File;


public class NVRomOperation {

    private static final String NVROM_BLOCK_DEV = "/dev/block/by-name/privdata";
    private static NVRomOperation sInstance;

    private NVRomOperation() {
    }

    public static synchronized NVRomOperation getInstance() {
        if (sInstance == null) {
            synchronized (NVRomOperation.class) {
                if (sInstance == null) {
                    sInstance = new NVRomOperation();
                }
            }
        }
        return sInstance;
    }

    public boolean isExistNVROM() {
        File file = new File(NVROM_BLOCK_DEV);
        return file.exists() && file.canRead() && file.canWrite();
    }


    /**
     * @param key   max length of key is 64
     * @param value
     * @return
     */
    public native boolean setIntegerNVRom(String key, int value);

    public native int getIntegerNVRom(String key, int defValue);

    public native boolean removeIntegerNVRom(String key);

    public native NVRomIntegerInfo[] getAllIntegerNVRom(int startOffset, int count);

    public native int getCountOfAllIntegerNVRom();

    /**
     * @param key    max length of key is 64
     * @param string max length of string is 1024
     * @return
     */
    public native boolean setStringNVRom(String key, String string);

    public native String getStringNVRom(String key);

    public native boolean removeStringNVRom(String key);

    public native NVRomStringInfo[] getAllStringNVRom(int startOffset, int count);

    public native int getCountOfAllStringNVRom();

    static {
        System.loadLibrary("NVRomData");
    }


}
